package com.hxzy.controller.api.system;

import com.hxzy.common.vo.R;
import com.hxzy.dto.system.DeptSearchDTO;
import com.hxzy.dto.system.SysUserDTO;
import com.hxzy.entity.system.SysUser;
import com.hxzy.service.system.SysDeptService;
import com.hxzy.service.system.SysUserService;
import com.hxzy.vo.system.SysDeptTreeVO;
import com.hxzy.vo.system.user.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "用户信息")
@RestController
@RequestMapping(value = "/api")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "分页查询用户")
    @PostMapping(value = "/sysUser/data")
    public R selectAll(@RequestBody SysUserDTO userDTO){
        return R.success(this.sysUserService.selectAll(userDTO));
    }

    @ApiOperation(value = "树形分页查询用户")
    @GetMapping(value = "/sysUser/findTreeUser")
    public R findTreeUser(Long id){
        return R.success(this.sysUserService.findTreeUser(id));
    }



    @ApiOperation(value = "新增需要的数据")
    @GetMapping(value = "/sysUser/addData")
    public R addData(){
        return R.success(this.sysUserService.addData());
    }

    @ApiOperation(value = "新增或则修改")
    @PostMapping(value = "/sysUser/addorUpdate")
    public R addorUpdate(@RequestBody UserVO user){
        if (user.getId()!=null){
            this.sysUserService.up(user);
        }else {
            this.sysUserService.add(user);
        }
        return R.success();
    }

    @ApiOperation(value = "根据id查用户")
    @GetMapping(value = "/sysUser/findUser")
    public R findUser(Long id){
        return R.success(this.sysUserService.findUser(id));
    }
}
